package com.suxii.handler;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;


@ChannelHandler.Sharable
@Slf4j
public class PingHandler extends ChannelDuplexHandler {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        // TODO 强转报错
        if (!(evt instanceof IdleStateEvent)) {
            return;
        }
        IdleStateEvent event=(IdleStateEvent) evt;
        if (event.state() == IdleState.READER_IDLE) {
            //if (ctx.channel().isActive()) {
                log.info("{},客户端没有心跳，释放channel",ctx.channel());
                StateHandler.noActive(ctx);
            //}
        }
    }
}
